<?php
	session_start();
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");
	$comments=mysql_query("SELECT pubcomments.ID, concat(users.firstName, ' ', users.lastName) AS fullName, users.mainPic, pubcomments.numberOfLikes, pubcomments.numberOfDislikes, pubcomments.whoLikes, pubcomments.whoDislikes, pubcomments.text FROM pubcomments JOIN users ON pubcomments.userId = users.ID WHERE picID={$_POST['snID']} ORDER BY id desc");                                     
	//$text=mysql_query("SELECT text FROM publications WHERE id={$_POST['snID']}");
	//$text=mysql_result($text, 0);
	echo "<div id='pubcomments'>";
	echo"<div id='headerLess'>";
	//echo ("<div id='textPublication'><p>".$text."</p></div>");
	echo "<div id='commentTextBox'><textarea id='pubCommentTextOfPublication' maxlength = '200'></textarea><div class = 'addPublicationCommentButton' id='".$_POST['snID']."' title='Add comment'><img src='add-comment.png'></div></div><br><br><br><br>";
	if (mysql_num_rows($comments)>0)
	{
	while ($result=mysql_fetch_array($comments, MYSQL_NUM))
	{
		echo "<dic id='".$result[0]."' class='wholeComment'><div class='PicOfCommenter'><img src='".$result[2]."mini.jpg'></div><div class='movingCommentsDiv'><div class='nameOfCommenter'><a href=http://sapme.net/Framework/profilePage.php?id=".$_SESSION['JID'].">".$result[1].":</a></div><img src='Icons/close.png' title = 'Delete comment' id=".$result[0]." class = 'deleteCommentOfPublicationButton'> <div class='textOfComment'>".$result[7]."</div><div id='commentLikes'> <img src = 'like.png' id='".$result[0]."' class = 'likePublicationCommentButton' title = 'Like this'> Likes: ".$result[3]."</div> <div id='commentDislikes'> <img src = 'dislike.png' id='".$result[0]."' class = 'dislikePublicationCommentButton' title = 'Dislike this'> Dislikes: ".$result[4]."</div></div><br><br><br><br><br><br><br>";
	}
	}
	echo "</div></div>";
	echo"<script>
		$('.addPublicationCommentButton').click(function()
		{
			$('.addPublicationCommentButton').removeClass('faraon');
			$(this).addClass('faraon');
			var theId = $('.faraon').attr('id');
			var text = $('#pubCommentTextOfPublication').val();
			$.post('addCommentPub.php', {pubID : theId, text : text}, function()
			{
				$.post('showCommentsPub.php', {snID : theId}, function(data)
				{
					$('#theFiuuuRotateTransformingCommentsDivHeaderless').html(data);
				});
			});
		});
		$('#pubCommentTextOfPublication').keypress(function(k)
		{
			if(k.keyCode == 13)
			{
				var theId = $('.addPublicationCommentButton').attr('id');
				var text = $('#pubCommentTextOfPublication').val();
				$.post('addCommentPub.php', {pubID : theId, text : text}, function()
				{
					$.post('showCommentsPub.php', {snID : theId}, function(data)
					{
						$('#theFiuuuRotateTransformingCommentsDivHeaderless').html(data);
					});
				});
			}
		});
		$('.likePublicationCommentButton').click(function()
		{
			$('.likePublicationCommentButton').removeClass('kucheVlachiReis');
			$(this).addClass('kucheVlachiReis');
			var theId = $('.kucheVlachiReis').attr('id');
			$.post('likeCommentPub.php', {pubID : theId}, function(data)
			{
				var publicationId = $('.addPublicationCommentButton').attr('id');
				$.post('showCommentsPub.php', {snID : publicationId}, function(kuche)
				{
					$('#theFiuuuRotateTransformingCommentsDivHeaderless').html(kuche);
				});
			});
		});
		$('.dislikePublicationCommentButton').click(function()
		{
			$('.dislikePublicationCommentButton').removeClass('TheKucheVlachiReis');
			$(this).addClass('TheKucheVlachiReis');
			var theId = $('.TheKucheVlachiReis').attr('id');
			$.post('dislikeCommentPub.php', {pubID : theId}, function(data)
			{
				var publicationId = $('.addPublicationCommentButton').attr('id');
				$.post('showCommentsPub.php', {snID : publicationId}, function(kuche)
				{
					$('#theFiuuuRotateTransformingCommentsDivHeaderless').html(kuche);
				});
			});
		});
		$('.deleteCommentOfPublicationButton').click(function()
		{
			$('.deleteCommentOfPublicationButton').removeClass('diraNqma');
			$(this).addClass('diraNqma');
			var theId = $('.diraNqma').attr('id');
			$.post('delPublicationComment.php', {commentID : theId}, function(data)
			{
				if(data != 'napsyvai')
				{
					var publicationId = $('.addPublicationCommentButton').attr('id');
					$.post('showCommentsPub.php', {snID : publicationId}, function(kuche)
					{
						$('#theFiuuuRotateTransformingCommentsDivHeaderless').html(kuche);
					});
				}
				else
				{
					var kuchi = 1;
					while(kuchi<10)
					{
						setInterval('zaek()', 500);
					}
					function zaek()
					{
						kuchi++;
						alert(kuchi);
					}
				}
			});
		});
	</script>";
	
?>

















































